Setup
Loading and installing packages in case it is necessary
list_of_packages <- c("tidyverse", "plotly", "shiny", "here", "DT")
new_packages <-
list_of_packages[!(list_of_packages %in% installed.packages()[, "Package"])]
if (length(new_packages))
install.packages(new_packages)
library(tidyverse)
library(plotly)
library(shiny)
library(here)
library(DT)
Defining the function I used to calculate distance
calc_flight_dist <- name <- function(dat) {
dat_dist <- {{dat}} %>%
dplyr::filter(!is.na(x_1)) %>%
dist() %>%
as.matrix()
return(sum((dat_dist[row(dat_dist) == col(dat_dist) + 1])))
}
Defining function I used to calculate all variables from flight trajectory
calc_flight_trajectory_vars <- function(dat) {
dat %>%
group_by(butterfly_flight) %>%
summarise(flight_dist = calc_flight_dist(.),
min_x = min(.$x_1, na.rm = T),
max_x = max(.$x_1, na.rm = T),
min_y = min(.$y_1, na.rm = T),
max_y = max(.$y_1, na.rm = T),
min_z = min(.$z_1, na.rm = T),
max_z = max(.$z_1, na.rm = T))
}
Defining the function I used to make the 3d plots
plots_flight_path <- function(dat) {
plot_ly(data = dat,
type = "scatter3d",
x = dat$x_1 ,
y = dat$y_1,
z = dat$z_1,
mode = "lines")
}
Processing the CSV files
Creats the dataframe that will receive the data from the flight paths
flights <-
tibble::tibble(
butterfly_flight = character(),
flight_dist = numeric(),
min_x = numeric(),
max_x = numeric(),
min_y = numeric(),
max_y = numeric(),
min_z = numeric(),
max_z = numeric()
)
b195 t1
Reads the data
b195_t1 <- readr::read_csv(here::here("unpaired-points", "b195-t1-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b195_t1")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b195_t1) %>%
dplyr::bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b195_t1)
b195 t2
Reads the data
b195_t2 <- readr::read_csv(here::here("unpaired-points", "b195-t2-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b195_t2")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b195_t2) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b195_t2)
b195 t3
Reads the data
b195_t3 <- readr::read_csv(here::here("unpaired-points", "b195-t3-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b195_t3")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b195_t3) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b195_t3)
b195 t4
Reads the data
b195_t4 <- readr::read_csv(here::here("unpaired-points", "b195-t4-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b195_t4")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b195_t4) %>%
bind_rows(flights, .)
flights
## # A tibble: 4 x 8
## butterfly_flight flight_dist min_x max_x min_y max_y min_z max_z
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 b195_t1 5.57 -0.177 0.0149 -1.14 -0.00254 -0.000718 1.86
## 2 b195_t2 3.75 -0.0269 0.437 -1.35 0.00112 0.0162 1.35
## 3 b195_t3 3.88 -0.0153 0.469 -1.40 0.0106 0.0118 1.32
## 4 b195_t4 3.98 -0.0902 0.0290 -1.60 0.0212 0.0104 2.00
Plots the trajectory
plots_flight_path(b195_t4)
b195 t5
Reads the data
b195_t5 <- readr::read_csv(here::here("unpaired-points", "b195-t5-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b195_t5")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b195_t5) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b195_t5)
b206 t1
Reads the data
b206_t1 <- readr::read_csv(here::here("unpaired-points", "b206-t1-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b206-t1")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b206_t1) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b206_t1)
b206 t2
Reads the data
b206_t2 <- readr::read_csv(here::here("unpaired-points", "b206-t2-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b206-t2")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b206_t2) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b206_t2)
b206 t3
Reads the data
b206_t3 <- readr::read_csv(here::here("unpaired-points", "b206-t3-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b206-t3")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b206_t3) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b206_t3)
b206 t4
Reads the data
b206_t4 <- readr::read_csv(here::here("unpaired-points", "b206-t4-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b206-t4")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b206_t4) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b206_t4)
b211 t1
Reads the data
b211_t1 <- readr::read_csv(here::here("unpaired-points", "b211-t1-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b211-t1")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b211_t1) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b211_t1)
b211 t2
Reads the data
b211_t2 <- readr::read_csv(here::here("unpaired-points", "b211-t2-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b211-t2")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b211_t2) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b211_t2)
b211 t3
Reads the data
b211_t3 <- readr::read_csv(here::here("unpaired-points", "b211-t3-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b211-t3")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b211_t3) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b211_t3)
b211 t4
Reads the data
b211_t4 <- readr::read_csv(here::here("unpaired-points", "b211-t4-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b211-t4")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b211_t4) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b211_t4)
b216 t1
Reads the data
b216_t1 <- readr::read_csv(here::here("unpaired-points", "b216-t1-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b216-t1")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b216_t1) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b216_t1)
b216 t2
Reads the data
b216_t2 <- readr::read_csv(here::here("unpaired-points", "b216-t2-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b216-t2")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b216_t2) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b216_t2)
b216 t4
Reads the data
b216_t4 <- readr::read_csv(here::here("unpaired-points", "b216-t4-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b216-t4")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b216_t4) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b216_t4)
b220 t2
Reads the data
b220_t2 <- readr::read_csv(here::here("unpaired-points", "b220-t2-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b220-t2")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b220_t2) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b220_t2)
b220 t3
Reads the data
b220_t3 <- readr::read_csv(here::here("unpaired-points", "b220-t3-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b220-t3")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b220_t3) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b220_t3)
b228 t1
Reads the data
b228_t1 <- readr::read_csv(here::here("unpaired-points", "b228-t1-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b228-t1")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b228_t1) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b228_t1)
b228 t2
Reads the data
b228_t2 <- readr::read_csv(here::here("unpaired-points", "b228-t2-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b228-t2")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b228_t2) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b228_t2)
b228 t3
Reads the data
b228_t3 <- readr::read_csv(here::here("unpaired-points", "b228-t3-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b228-t3")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b228_t3) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b228_t3)
b228 t4
Reads the data
b228_t4 <- readr::read_csv(here::here("unpaired-points", "b228-t4-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b228-t4")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b228_t4) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b228_t4)
b228 t5
Reads the data
b228_t5 <- readr::read_csv(here::here("unpaired-points", "b228-t5-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b228-t5")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b228_t5) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b228_t5)
b228 t6
Reads the data
b228_t6 <- readr::read_csv(here::here("unpaired-points", "b228-t6-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b228-t6")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b228_t6) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b228_t6)
b228 t7
Reads the data
b228_t7 <- readr::read_csv(here::here("unpaired-points", "b228-t7-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b228-t7")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b228_t7) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b228_t7)
b238 t1
Reads the data
b238_t1 <- readr::read_csv(here::here("unpaired-points", "b238-t1-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b238-t1")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b238_t1) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b238_t1)
b238 t2
Reads the data
b238_t2 <- readr::read_csv(here::here("unpaired-points", "b238-t2-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b238-t2")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b238_t2) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b238_t2)
b238 t4
Reads the data
b238_t4 <- readr::read_csv(here::here("unpaired-points", "b238-t4-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b238-t4")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b238_t4) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b238_t4)
b238 t5
Reads the data
b238_t5 <- readr::read_csv(here::here("unpaired-points", "b238-t5-unpaired-points-xyz.csv")) %>%
dplyr::mutate(butterfly_flight = "b238-t5")
Calculates the variables
flights <-
calc_flight_trajectory_vars(b238_t5) %>%
bind_rows(flights, .)
Plots the trajectory
plots_flight_path(b238_t5)
Table with all the data
flights %>%
DT::datatable(extensions = 'Buttons',
options = list(dom = 'Blfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
lengthMenu = list(c(10,25,50,-1),
c(10,25,50,"All"))))